<?php if(isset($breadcrumb)) { ?>
<div class="breadcrumb">
    <?php foreach($breadcrumb as $item) { ?>
    <a href="<?php echo $item['href']; ?>"><?php echo $item['text']; ?></a>
    <?php if($item['last'] == false) { ?>
        ::
        <?php } ?>
    <?php } ?>
</div>
<? } ?>
<?if(isset($message)) { ?>
<div class="success"><?=$message?></div>
<? } ?>
<div class="box">
<div class="heading">
    <h1><img src="<?=$theme_path?>images/admin/category.png" alt=""><?=$title?></h1>
    <div class="buttons">
        <? foreach($actions as $item) { ?>
        <a onclick="$('#form').attr('action','<?=$item['href']?>');$('#form').submit();" class="button"><?=$item['text']?></a>
        <? } ?>
    </div>
</div>
<div class="content">
<form method="post" enctype="multipart/form-data" id="form">

   <table class="form">
        <tbody>
        <?php foreach($fields as $item) { ?>
        <tr id="row_<?=$item['name']?>" <?=(isset($item['type']) && $item['type'] == 'hidden')?'style="display:none"':''?>>
            <td><?=$item['text']?></td>
            <td>
                <? if($item['type'] == 'text') { ?>
                <input type="text" name="<?=$item['name']?>" size="100" value="<?=$item['value']?>" />
                <? } else if($item['type'] == 'label') { ?>
                    <?=$item['value']?>
				<? } else if($item['type'] == 'hidden') { ?>
				<input type="hidden" name="<?=$item['name']?>" value="<?=$item['value']?>" />
                <? } else if($item['type'] == 'textarea') { ?>
                <textarea name="<?=$item['name']?>" rows="10" cols="150"><?=$item['value']?></textarea>
                <? } else if($item['type'] == 'checkbox') { ?>
                <input type="checkbox" name="<?=$item['name']?>"></input>
                <? } else if($item['type'] == 'select') { ?>
                <select name='<?=$item['name']?>'>
                    <? foreach($item['options'] as $option) { ?>
                    <option value="<?=$option->{$item['select_value']}?>" <?=$option->{$item['select_value']} == $item['value'] ? 'selected=""' : '' ; ?>><?=$option->{$item['select_display']}?></option>
                    <? } ?>
                </select>
                <? } else if($item['type'] == 'image') { ?>
					<img src="<?=base_url().$item['value']?>" style="max-width:300px; max-height:200px"/><br/>
                <? } else if($item['type'] == 'file') { ?>
					<input type="file" name="<?=$item['name']?>" value="<?=$item['value']?>">
                <? } else if($item['type'] == 'add_file') { ?>
                    <input type="button" onclick="add_new_file()" value="<?=$item['text']?>"></input>
                    <script type="text/javascript">
                        $file_id = 0;
                        function add_new_file()
                        {
                            $file_id++;
                            var tr = $('<tr>');
                            tr.append('<td>');
                            var td = $('<td>');
                            var new_file = $('<input type="file">');
                            new_file.attr('name',"<?=$item['name']?>" + $file_id);
                            td.append(new_file);
                            var button = $('<input type="button" value="Xóa hình này">');
                            button.click(function(){
                                tr.remove();
                            });
                            td.append(button);
                            tr.append(td);
                            $('.form').append(tr);
                        }
                    </script>
				<? } else if($item['type'] == 'images') {
					if(!$item['value'])
						echo "Chưa có hình";
					else {
						foreach($item['value'] as $item) {
						?>
						<div class="image-cover" id="item_<?=$item->id?>"> <img src="<?=$item->thumb_image?>" />
							<div class="action"><a class="delete" href="javascript:;" onclick="javascript:delImg('<?=$item->image_id?>') ">Xóa</a></div>
							<input type="hidden" name="image_del_id[]" value="<?=$item->image_id?>"/>
							<input type="hidden" id="image_del_<?=$item->image_id?>" name="image_del[]" value="false"/>
						</div>

					<?
						}
					}
				} ?>

            </td>
        </tr>
        <?php } ?>

        </tbody>
    </table>
</form>
<div class="buttons">
        <? foreach($actions as $item) { ?>
        <a onclick="$('#form').attr('action','<?=$item['href']?>');$('#form').submit();" class="button"><?=$item['text']?></a>
        <? } ?>
    </div>
</div>
</div>
